import QtQuick 2.10
import QtQuick.Window 2.10
import QtQuick.Controls 2.2
import Toou2D 1.0
import cn.conchit 1.0

Item {
    id: item_test
    height: parent.height

    focus: true


    //标签列表
    TLabelList{
       id: labelList
       z: 1
    }

    //分割线(标签列表-图片列表)
    TDividerLine{
        id: dividerLine1
        anchors.top: labelList.bottom
        width: labelList.width;
        height: 5;
        z: 1

    }

    //图片列表
    TImageList {
        id: imageList
        width:labelList.width;
        anchors.top: dividerLine1.bottom
        z: 1
    }

    //分割线(标签列表-图像显示)
    TDividerLine{
        id: dividerLine2
        anchors.left: labelList.right
        width: 3;
        height: parent.height;
        z: 1
    }

    //图像操作
    TImageOperateArea {
        id: imageOperateArea
        anchors.right: parent.right
        z: 1
    }

    //分割线(图像显示-图像操作)
    TDividerLine{
        id: dividerLine3
        anchors.right: imageOperateArea.left
        width: 3;
        height: parent.height;
        z: 1
    }

    TImageShowArea {
        id: imageShowArea
        anchors.left: dividerLine2.right
    }


    Connections {
        target: labelList
        function onLabelSelected(newLabel) {
            imageShowArea.changeLabelSel(newLabel);
        }
    }


    Connections {
        target: imageOperateArea
        function onOpenImageFolder(currentFolder) {
            imageList.openImageFolder(currentFolder);
        }

        function onSetSavePath(currentFolder) {
            labelList.setSavePath(currentFolder);
            ImageModel.setSavePath(currentFolder);
        }

        function onOpenDealWithStep(step) {
            imageList.openDealWithStep(step);
        }
        function onClearAll() {
            imageShowArea.clearAll();
        }

        function onRemoveLast() {
            imageShowArea.removeLast();
        }
    }

    Connections {
        target: imageList
        function onDealWithImage(index) {
            imageShowArea.dealWithImage(index)
        }
    }



    Component.onCompleted: {
        item_test.forceActiveFocus();
    }

    Keys.onPressed: (event)=> {
        if (event.key === Qt.Key_Left || event.key === Qt.Key_A) {
             imageList.openDealWithStep(-1);
             event.accepted = true;
        }

        if (event.key === Qt.Key_Right || event.key === Qt.Key_D) {
             imageList.openDealWithStep(1);
             event.accepted = true;
        }

        if (event.key === Qt.Key_Up || event.key === Qt.Key_W) {
             labelList.labelSelectChange(-1);
             event.accepted = true;
        }

        if (event.key === Qt.Key_Down || event.key === Qt.Key_S) {
             labelList.labelSelectChange(1);
             event.accepted = true;
        }

        if(event.key === Qt.Key_Z && event.modifiers & Qt.ControlModifier) {
            imageShowArea.removeLast();
            event.accepted = true;
        }

    }




}


